package com.cluster.platform.controller;

import com.cluster.platform.common.api.CommonResult;
import com.cluster.platform.dao.UmsUserDetailDao;
import com.cluster.platform.dto.UmsUserDetailDto;
import com.cluster.platform.model.UmsAdmin;
import com.cluster.platform.service.UmsUserDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户详情信息
 * @ClassName: UmsUserDetailController
 */
@Controller
@Api(tags = "UmsUserDetailController", value = "用户详细信息")
@RequestMapping("/userDetail")
public class UmsUserDetailController {

    @Autowired
    private UmsUserDetailService umsUserDetailService;

    /**
     * 根据用户id查询用户信息
     * @param userId
     * @return
     */
    @ApiOperation("查询用户详情信息")
    @RequestMapping(value = "/searchByUserId", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<UmsUserDetailDto> searchByUserId(@RequestParam("userId") String userId) {
        return umsUserDetailService.searchByUserId(userId);
    }

    /**
     * 根据用户名及用户id更新用户信息
     * @param umsUserDetailDto
     * @return
     */
    @ApiOperation("更新用户详情信息")
    @RequestMapping(value = "/updateUserDetail", method = RequestMethod.PUT)
    @ResponseBody
    public CommonResult<UmsUserDetailDto> updateUserDetail(@RequestBody UmsUserDetailDto umsUserDetailDto) {
        return umsUserDetailService.updateUserDetail(umsUserDetailDto);
    }

    /**
     * 逻辑删除
     */
    @ApiOperation("删除用户详情信息")
    @RequestMapping(value = "/deleteUserDetail", method = RequestMethod.DELETE)
    @ResponseBody
    public CommonResult<Object> deleteUserDetail(@RequestParam("userId") String userId) {
        return umsUserDetailService.deleteUserDetail(userId);
    }

    /**
     * 新增用户详细信息
     */
    @ApiOperation("新增用户详情信息")
    @RequestMapping(value = "/addUserDetail", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<UmsUserDetailDto> addUserDetail(@RequestBody UmsUserDetailDto umsUserDetailDto) {
        return umsUserDetailService.insertUmsUserDetail(umsUserDetailDto);
    }

    /**
     * 批量删除用户信息
     */
    @ApiOperation("批量删除用户信息")
    @RequestMapping(value = "/batchDeleteUser", method = RequestMethod.PUT)
    @ResponseBody
    public CommonResult<Object> batchDeleteUser(List<UmsAdmin> umsAdmins) {
        return umsUserDetailService.batchDeleteUserDetail(umsAdmins);
    }

    /**
     * 根据用户名查询用户信息
     */
    @ApiOperation("根据用户名查询用户信息")
    @RequestMapping(value = "/searchByUsername", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<UmsUserDetailDto> searchByUsername(String username) {
        return umsUserDetailService.searchByUsername(username);
    }
}
